<!-- mate start -->
<?php $this->load->view('assists/mate.php') ?>
<!-- mate end -->
<link rel="stylesheet" href="<?=base_url('static/index/css/login.css')?>" />
<title>用户登录</title>
<!-- header strat -->
<?php $this->load->view('assists/header.php') ?>
<!-- header end -->
    <div id="top-alert" class="fixed alert-success" style="display:none;">
    	<button class="close fixed" >×</button>
    	<p class="alert-content">这是内容</p>
    </div>
    <div id="login">
    	<div class="login">
        	<h2 class="login_tit">
            	<p>账户登录</p>
            </h2>
            <div class="login_content">
            	<form action="<?=site_url('Login/tologin')?>" method="post" class="login_form">
            		<input type="hidden" id="url" name="url" value="<?=$_SERVER['HTTP_REFERER']?>" />
	            	<div class="content">
	                	<h2>用户名</h2>
	                    <div class="content_input">
	                    	<input type="text" name="username" id="username" value="" placeholder="请你输入用户名" alt="用户名" />
	                    </div>
	                </div>
	                <div class="content">
	                	<h2>密码</h2>
	                    <div class="content_input">
	                    	<input type="password" name="password" id="password" value="" placeholder="请输入密码" alt="密码" />
	                    </div>
	                </div>
	                <div class="login_check">
	                	<h2>验证码</h2>
	                    <div class="login_check_input clearfix">
	                    	<input type="text" name="code" id="code" value="" placeholder="请输入验证码" alt="验证码" />
	                        <p><img src="<?=site_url('Assists/captcha')?>" onclick="this.src='<?=site_url('Assists/captcha')?>?'+Math.random()"></p>
	                    </div>
	                </div>
	                <div class="login_btn">
	                	<input type="button" value="登录" id="login_btn" />
	                </div>
            	</form>
            
            	<div class="login_content_rigth">
                	<h2>没有账号？ <a href="<?=site_url('Register')?>">注册账号</a></h2>
                    <div class="login_question">
                    	<h2>登录后可以？</h2>
                        <ol class="login_question_ol">
                        	<li>发布和分享众创想法</li>
                            <li>对评论想法进行品论</li>
                        </ol>
                    </div>
                </div>
            </div>
        </div>
    </div>
    
    <!-- footer start -->
   	<?php $this->load->view('assists/footer.php') ?>
   	<!-- footer end -->
   	<script type="text/javascript">
   		$("#login_btn").click(function(){
   	   		var url = $(".login_form").get(0).action;
   	   		var postData ={
   	    	   	"username" : $("#username").val(),
   	    	   	"password" : $("#password").val(),
   	    	   	"code" : $("#code").val(),
   	    	   	"url" : $("#url").val()
   	    	}
	   	   	for(var x in postData){
				if(postData[x].length==0){
					var tipTxt = $("#"+x).attr("alt")
					alert(tipTxt+"不允许为空！");
					$("#"+x).focus();
					return false;
				}
			}
			$.post(url,postData,function(data){
				if(data.flag == 0){
        			alert(data.content);
        		}else if(data.flag == 1){
        			updateAlert(data.content,true);
        			setTimeout(function(){
    					if(data.url)
    					{
    						location.href=data.url;
    					}
    					else{
    						location.reload();
    					}
    				},1500);
        		}else if(data.flag ==-1){
        			updateAlert(data.content);
        		}
			},"json");
			//警告栏显示
			var am_alert = $('#top-alert');
			var alert_button = am_alert.find('button');
			alert_button.click(function(){
				am_alert.hide();
			});
			window.updateAlert = function(text,c)
			{
				text = text||'default';
				c = c||false;
				am_alert.css("display","block");
				if(text!='default'){
					am_alert.find('p').text(text);
				}
				else{
					am_alert.find('p').text('这是内容!');
				}
				if(c==false)
				{
					am_alert.removeClass("alert-success").addClass(' alert-error');
				}else{
					am_alert.removeClass("alert-error").addClass(" alert-success");
				}
			}
   	   	});
   	</script>
</body>
</html>